using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using ComputerShopE3.Models;

namespace ComputerShopE3.Controllers
{
    public class BankAcountController : Controller
    {
        ComputerShopDBEntities1 _db = new ComputerShopDBEntities1();
        //
        // GET: /BankAcount/

        public ActionResult Index()
        {
            return View(_db.NGAN_HANG.ToList());
        }

        //
        // GET: /BankAcount/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /BankAcount/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /BankAcount/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude="id")]NGAN_HANG nganHangToCreate)
        {
            try
            {
                _db.AddToNGAN_HANG(nganHangToCreate);
                _db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /BankAcount/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(_db.NGAN_HANG.Where(nh=>nh.id==id).First());
        }

        //
        // POST: /BankAcount/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(NGAN_HANG nhToEdit)
        {
            try
            {
                NGAN_HANG originalNganHang = _db.NGAN_HANG.Where(nh => nh.id == nhToEdit.id).First();
                _db.ApplyPropertyChanges(originalNganHang.EntityKey.EntitySetName, nhToEdit);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
